import React from 'react';
import * as THREE from 'three';
import Scene from '../Scene';
let group = new THREE.Group();
export default class TestModel {
    constructor(){
        this.scene = new Scene();
        this.canvasScene = this.scene.scene;
        this.renderer = this.scene.renderer.renderer;
        this.canvas = this.scene.canvas;
        this.camera = this.scene.camera.perspectiveCamera;
        // 了解WebGLRenderTarget使用场景
        this.init();
    }
    init(){
        let that = this;
        let buffer = new THREE.WebGLRenderTarget(1000, 1000);
        let planeGeometry = new THREE.PlaneGeometry(50, 50);
        let planeMtl = new THREE.MeshPhysicalMaterial({
            map:buffer.texture
        });
        console.log(planeMtl);
        console.log(buffer);
        
        const bufferScene = new THREE.Scene();
        let boxGeometry = new THREE.BoxGeometry(10, 10, 10);
        let boxMtl = new THREE.MeshBasicMaterial({ color:'#00ff00' });
        bufferScene.add(new THREE.Mesh(boxGeometry, boxMtl));
        let planeMesh = new THREE.Mesh(planeGeometry, planeMtl);
        // planeMesh.rotateX(-Math.PI / 2);
        this.canvasScene.add(planeMesh);
        
        function render(){
            that.renderer.setRenderTarget(buffer);
            that.renderer.render(bufferScene, that.camera);
            that.renderer.setRenderTarget(null);
            
            requestAnimationFrame(render);
        }
        render();
        
    }
    
}